package com.parfinex.sims.dao;

import com.parfinex.sims.entity.ClassInfo;
import com.parfinex.sims.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.Test;

import java.sql.SQLException;
import java.util.List;

/**
 * Description:
 *
 * @author lijh
 * @version 1.0
 * @date 2021-11-14 13:45
 */
public class ClassDao {
    /**查询班级信息 */
    @Test
    public List<ClassInfo> selectClass(String className) throws SQLException {
        /**1.获取一个QueryRunner对象 */
        QueryRunner queryRunner = new QueryRunner(DruidUtils.dataSource);
        /**编写SQL语句*/
        /*String sql = "select class_name,grade_name,master_teacher,class_slogan,class_number_count from class_info where class_name=?";*/
        String sql = "select * from class_info where className like ?\"%\" ";
//        String sql = "select * from class_info";
        System.out.println(sql);
        List<ClassInfo> classQuery = queryRunner.query(sql,new BeanListHandler<ClassInfo>(ClassInfo.class),className);

        return classQuery;
    }
    /**新增班级信息 */
    public int updateClass(ClassInfo classInfo) throws SQLException {
        //1.获取一个QueryRunner对象
        QueryRunner queryRunner = new QueryRunner(DruidUtils.dataSource);
        //2.编写SQL语句
        String sql = "insert into class_info (className,gradeName,masterTeacher,classSlogan,classNumberCount) values(?,?,?,?,?)";
        Object[] param = {classInfo.getClassName(),classInfo.getGradeName(),classInfo.getMasterTeacher(),classInfo.getClassSlogan()
                ,classInfo.getClassNumberCount()};

        //3.执行写入操作，并作为返回值对象
        return queryRunner.update(sql,param );
    }
    /**删除班级信息*/
    public int deleteClass(ClassInfo classInfo){
        return 0;
    }
}